/**
 * 
 */
package com.vector.ding.commons;

import net.sf.json.JSONObject;

/**
 * web request result util class
 * @author vector
 */
public class ActionResult {

	/**
	 * no way to instance
	 */
	private ActionResult() {
		
	}
	
	/**
	 * success result with no content 
	 * <code>{"success": true}</code>
	 * @return
	 */
	public static JSONObject success() {
		return result(Constant.RESULT_SUCCESS, null, null);
	}
	
	/**
	 * success with content operator result 
	 * <code>{"success":true, "content": content}</code>
	 * @param content
	 * @return
	 */
	public static JSONObject success(String content) {
		return result(Constant.RESULT_SUCCESS, content, null);
	}
	
	/**
	 * error result
	 * <code>{"success":false, "error": error}</code>
	 * @param error
	 * @return
	 */
	public static JSONObject fail(String error) {
		return result(Constant.RESULT_FAILURE, null, error);
	}
	
	public static JSONObject result(
			boolean success, String content, String error) {
		JSONObject result = new JSONObject();
		result.put(Constant.RESULT_SUCCESS_KEY, success);
		if (null != content)
			result.put(Constant.RESULT_CONTENT_KEY, content);
		if (null != error)
			result.put(Constant.RESULT_ERROR_KEY, error);
		
		return result;
	}
}
